<template>
    <el-container class="adminWrap" v-if="isAdmin">

        <el-header>
            <header-nav></header-nav>
        </el-header>

        <el-container class="secondWrap">

            <el-aside>
                <left-side-bar></left-side-bar>
            </el-aside>

            <el-main>
                <router-view></router-view>
            </el-main>

        </el-container>
    </el-container>

</template>

<script>
import LeftSideBar from "components/content/admin/LeftSideBar.vue"
import HeaderNav from "components/content/admin/HeaderNav.vue"
import request from "api/index.js"

export default {
    data(){
        return {
            isAdmin:false,
        }
    },
    components:{
        LeftSideBar,
        HeaderNav,
    },
    beforeCreate () {
        if(sessionStorage.getItem('token')){
        request({
            method:"post",
            url:"log/testAdmin.php",
            data:{
                token:sessionStorage.getItem("token")
            }
        }).then(res=>{
            if(res.loginState != "SUCCESS"){
                this.$message({
                    message:"无权访问"
                })
                this.$router.replace("/main")
            }else{
                this.isAdmin = true
            }
        })}else{
            this.$message({
                message:"没有登录或者登录失效"
            })
            this.$router.replace("/login")
        }
    },
    mounted(){

    }
}
</script>

<style scoped>
.adminWrap{
    height: 100%;
    width: 100%;
}
.secondWrap{
    height: calc(100% - 60px);
}
.content-wrap{
    height: 100%;
    overflow: scroll;
    position: relative;
}
.el-aside{
    width: 250px !important;
    background:#2f3447;
    overflow: hidden;
}
.el-header{
    padding:0;
    height: 60px;
}
.el-main{
    overflow: hidden;
    padding: 5px;
}
</style>

<style>
.el-table .el-button + .el-button {
  margin: 0;
}
</style>